package com.sx.pipeline.repos.local.db

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import com.sx.mvvmlibs.utils.Logs
import com.sx.pipeline.repos.local.db.dao.PipeFileBeanDao
import com.sx.pipeline.repos.local.db.table.PipeFileBeanDO

/**
 * @Author: YY
 * @Date: 2022/8/10
 * @Desc: TODO
 */
@Database(entities = [PipeFileBeanDO::class], version = 1, exportSchema = false)
abstract class AppDB: RoomDatabase() {

    // 文件操作 Dao层
    abstract fun pipeFileBeanDao(): PipeFileBeanDao

    companion object {
        @Volatile private var INSTANCE: AppDB? = null
        fun getInstance(): AppDB =
            (INSTANCE ?: synchronized(this) {
                RoomUtils.getDB(
                    AppDB::class.java, "pipeLine-db",
                    object : RoomDatabase.Callback() {
                        override fun onCreate(db: SupportSQLiteDatabase) {
                            super.onCreate(db)
                            Logs.d("onCreate RoomDatabase ${db.path}")
                        }
                    })
            })
    }
}